package com.swinw.asumall.cart.config;

import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 向容器中添加一个线程池
 */
@Component
public class MyTheadConfig {

    /**
     * corePoolSize : 核心线程数
     * maximumPoolSize：最大线程数
     * keepAliveTime:最大空闲时间
     * TimeUnit.SECONDS ： 时间单位
     * new LinkedBlockingDeque<>(100000)：阻塞队列大小
     * Executors.defaultThreadFactory()：使用的线程工厂
     * new ThreadPoolExecutor.AbortPolicy() ：拒绝策略
     * @return
     */
    @Bean
    public ThreadPoolExecutor threadPoolExecutor(){
        return new ThreadPoolExecutor(
                20,
                100,
                10,
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(100000),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
    }
}
